package com.ml.doctor.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.ml.doctor.R;


public class TabIndicator {

    private CharSequence mLabel;
    private int mIcon;
    private int mIndicatorId;
    private Context mContext;

    public TabIndicator(Context context, CharSequence label) {
        mContext = context;
        mLabel = label;
    }

    public TabIndicator(Context context, CharSequence label, int indicatorId) {
        this(context, label);
        mIndicatorId = indicatorId;
    }

    public TabIndicator(Context context, CharSequence label, int icon, int indicatorId) {
        this(context, label, indicatorId);
        mIcon = icon;

    }

    public View createIndicatorView(TabHost mTabHost) {
        if (mIndicatorId <= 0) {
            mIndicatorId = R.layout.tab_indicator;
        }
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View tabIndicator = inflater.inflate(mIndicatorId, mTabHost.getTabWidget(), false);

        final TextView tv = (TextView) tabIndicator.findViewById(android.R.id.title);
        tv.setText(mLabel);

        final TextView tip = (TextView) tabIndicator.findViewById(R.id.ic_new_text);
        if (tip != null) {
            tip.setVisibility(View.GONE);
        }

        do {
            final ImageView ig = (ImageView) tabIndicator.findViewById(android.R.id.icon);
            if (ig == null)
                break;
            if (mIcon > 0) {
                ig.setImageResource(mIcon);
                ig.setVisibility(View.VISIBLE);
            } else {
                ig.setVisibility(View.GONE);
            }
        } while (false);
        return tabIndicator;
    }

}
